﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace GTP.AppFrame.PrototypeTools.Common
{
    /// <summary>
    /// 日志类，记录异常日志
    /// </summary>
    public static class Log
    {
        /// <summary>
        /// 添加错误日志
        /// </summary>
        /// <param name="title"></param>
        /// <param name="message"></param>
        public static void AddErrorLog(string title, string message)
        {
            message = string.Format("{0}\t{1}\t{2}", DateTime.Now, title, message);
            string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Output\\Log");
            if (!Directory.Exists(fileName))
            {
                Directory.CreateDirectory(fileName);
            }
            fileName = string.Format("{0}\\{1}.txt", fileName, DateTime.Now.ToString("yyyyMMdd"));
            using (StreamWriter writer = new StreamWriter(fileName, true))
            {
                writer.WriteLine(message);
            }
        }
    }
}
